package com.erp.domain;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;

import com.erp.dto.Role;

@SuppressWarnings("serial")
@Entity
@Table(name = "t_role")
public class TRole implements java.io.Serializable {

	/**
	 * 默认构造方法
	 */
	public TRole() {
	}

	/**
	 * 将数据传输对象转化为持久化对象
	 * 
	 * @param role
	 */
	public TRole(Role role) {
		this.id = role.getId();
		this.sign = role.getSign();
		this.name = role.getName();
		this.description = role.getDescription();
	}

	private Integer id;
	private String sign;
	private String name;
	private List<TPrivilege> privileges = new ArrayList<TPrivilege>(0);
	private String description;

	@Id
	@GeneratedValue
	@Column(name = "id")
	public Integer getId() {
		return this.id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	@Column(name = "sign")
	public String getSign() {
		return sign;
	}

	public void setSign(String sign) {
		this.sign = sign;
	}

	@Column(name = "name")
	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	/**
	 * privileges属性，本类与TPrivilege的多对多单向关系
	 * 
	 * @return
	 */
	@ManyToMany
	@JoinTable(name = "t_role_privilege", joinColumns = @JoinColumn(name = "role_id"), inverseJoinColumns = @JoinColumn(name = "privilege_id"))
	@OrderBy("orderNumber")
	public List<TPrivilege> getPrivileges() {
		return privileges;
	}

	public void setPrivileges(List<TPrivilege> privileges) {
		this.privileges = privileges;
	}

	@Column(name = "description")
	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

}